<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="../../mytags.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>巡检申请</title>
    <t:base type="jquery"></t:base>
    <script type="text/javascript" src="webpage/com/wx/added_product/procurement/shoppingCar.js"></script>
    <link rel="stylesheet" href="webpage/com/wx/wx-plug-in/plugin/picker/css/mui.picker.all.css">
    <script type="text/javascript" src="webpage/com/wx/wx-plug-in/plugin/picker/js/mui.picker.all.js"></script>
    <script type="text/javascript" charset="utf-8">
        mui.init();
    </script>
    <style>
        .mui-table-view-cell{
            padding:5px 10px !important;
        }
    </style>
</head>
<body>
<div class="fp_t">申请信息</div>
<%--<div class="eer">

    <table class="skey_con">
        <tr>
            <td class="tes">设备序列号</td>
            <td class="sk_tt"><span id="snSpan"></span></td>
        </tr>
        <tr>
            <td class="tes">期望巡检时间</td>
            <td class="sk_tt"><input type="text" id="expectDate" name="expectDate" class=" mui-input" style="width:98%; margin-bottom: 0; height: 30px; margin: 5px 0; font-size: 14px;"/>
        </tr>
    </table>
</div>--%>
<div class="mui-clearfix"></div>
<div class="mui-card pps"  style="margin:0px;"> <span style="width:100%;padding-left:5px;font-size:12px;margin:2px 0 2px 0;">
    尊敬的客户，如果您有指定具体日期的要求请与中影巴可服务热线<a href="tel:400-88-22726" style="color:blue">400-88-22726</a>联系。
    </span>
</div>
<t:formvalid formid="formobj" dialog="false" usePlugin="password" layout="table" action="inspectionWx.do?doSign"
             tiptype="tipType" validFormName="formValidName" showAllError="false" callback="subcallback">
    <div class="kow" style="margin-top: 10px;margin-bottom: 40px;">
        <input type="hidden" id="equipmentIdStr" name="equipmentIdStr" value="${equipIds}"/>
        <input type="hidden" id="equipmentTypeStr" name="equipmentTypeStr" value="${types}"/>
        <%--微信端创建巡检预约默认为处理中--%>
        <input type="hidden" id="status" name="status" value="0"/>
        <input type="hidden" id="source" name="source" value="0"/>
        <input type="hidden" id="cinemaId" name="cinema.id" value="${contact.belongCinema.id}"/>
        <ul class="mui-table-view">
            <li class="mui-table-view-cell">
                <span style="width: 100px; float: left; line-height: 40px; font-size: 14px; text-align: right; padding-right: 10px;">设备序列号 </span>
                <div class="mui-input-row">
                    <div id="snSpan" class="inrr" style="width:98%;word-wrap:break-word;word-break:break-all;padding:8px;font-size:14px;line-height:24px;"/>
                </div>
            </li>
            <li class="mui-table-view-cell" style="margin-top: 0;">
                <span style="width: 100px; float: left; line-height: 40px; font-size: 14px;text-align: right; padding-right: 10px">期望巡检年度</span>
                <div class="mui-input-row">
                    <select name="expectDate" class="sele mui-icon mui-icon-arrowdown" style="margin-top: 2px;">
                        <option value="">---请选择---</option>
                        <c:forEach var="year" items="${years}">
                            <option value="${year}-01-01"
                                    <c:if test="${year eq expectDate}">
                                        selected
                                    </c:if>
                            >${year}</option>
                        </c:forEach>
                    </select>
                </div>
            </li>

            <li class="mui-table-view-cell" style="margin-top: 0;">
                <span style="width: 100px; float: left; line-height: 40px; font-size: 14px;text-align: right; padding-right: 10px">期望巡检季度</span>
                <div class="mui-input-row">
                    <select name="expectSection"  id="expectSection" class="sele mui-icon mui-icon-arrowdown" style="margin-top: 2px;">
                        <option value="">---请选择---</option>
                    </select>
                </div>
                <div style="float: left;width: 100%;font-size: 12px;padding-left:6px;color:gray;">
                    系统仅可预约下一季度之后的巡检，如您有其它服务要求请联系中影巴可服务热线<a href="tel:400-88-22726" style="color:blue">400-88-22726</a>
                </div>
            </li>
            <li class="mui-table-view-cell">
                <span style="width: 100px; float: left; line-height: 40px; font-size: 14px; text-align: right; padding-right: 10px;">联系人姓名 </span>
                <div class="mui-input-row">
                    <input id='contactName' name="contactName" type="text" class=" mui-input"
                           nullmsg="请填写联系人信息"
                           style="width:98%; margin-bottom: 0; height: 30px; margin: 5px 0; font-size: 14px;"
                           value="${contact.tsBaseUser.realName}">
                </div>
            </li>
            <li class="mui-table-view-cell" style="margin-top: 0;">
                <span style="width: 100px; float: left; line-height: 40px; font-size: 14px;text-align: right; padding-right: 10px">电话</span>
                <div class="mui-input-row">
                    <input id='phone' name="phone" type="text" class=" mui-input" datatype="cPhone" nullmsg="请填写电话信息"
                           style="width:98%; margin-bottom: 0; height: 30px; margin: 5px 0; font-size: 14px;"
                           value="${contact.cellphone1}">
                </div>
            </li>
            <li class="mui-table-view-cell">
                <span style="width: 100px; float: left; line-height: 40px; font-size: 14px; text-align: right; padding-right: 10px;">邮箱 </span>
                <div class="mui-input-row">
                    <input id='mail' name="mail" type="text" class=" mui-input" datatype="e" nullmsg="请填写邮箱信息"
                           style="width:98%; margin-bottom: 0; height: 30px; margin: 5px 0; font-size: 14px;"
                           value="${contact.email}">
                </div>
            </li>
            <li class="mui-table-view-cell" style="margin-top: 0;">
                <span style="width: 100px; float: left; line-height: 40px; font-size: 14px;text-align: right; padding-right: 10px">服务要求</span>
                <textarea class="ww" style="width: 70%" id='content' name="content"></textarea>
            </li>
        </ul>
    </div>
</t:formvalid>
<%--<div class="mui-content-padded" >
    <a class="mui-btn mui-btn-block mui-btn-primary"  style="position:fixed;bottom:0px;padding-left:0px;"></a>
</div>--%>
<div style="position: fixed;bottom:2px;width:98%;left:2%">
    <a class="mui-btn mui-btn-block mui-btn-primary" href="#" id="sub" >提交</a>
</div>
</body>
<script type="text/javascript">
    function expectDateChange(){
        var _this = $("select[name='expectDate']");
        var _o =$("select[name='expectSection']");
        _o.children().not(":first").remove();
        if(_this.val()==''){
            _o.children().not(":first").remove();
            _o.children(":first").attr("selected","selected");
            return;
        }
        $.getJSON("cbsInspectionAppointmentController.do?getExpectionByType&value="+_this.val().substring(0,4),{},function(data){
            var optionArray = new Array();
            $.each(data,function(idx,itm){
                optionArray.push("<option value='"+itm.index+"'>"+itm.name+"</option>")

            })
            _o.append(optionArray.join(""));
            if(eSection > 0){
                _o.find("[value='"+eSection+"']").attr("selected","selected");
                eSection = 0;
            }else{
                if(optionArray.length ==1){
                    _o.children(":last").attr("selected","selected");
                }
            }

        })
    }
    function subcallback(data) {
        var msg = "您的服务申请已提交，申请号:"+data.msg;
        mui.confirm(msg,'提示',['确定'],function(e){
            mui.openWindow({
                url: 'inspectionWx.do?list',
                createNew: true
            })
        });
    }
    /**验证提示*/
    function tipType(msg, o, cssctl) {
        if (o.type == 3) {
            mui.toast(msg);
        }
    }

    function sub(){
        var contactName = $("#contactName").val();
        if(contactName == ""){
            mui.toast("请填写联系人姓名");
            return;
        }
        if(contactName.length > 8){
            mui.toast("联系人姓名过长");
            return;
        }
        $("#sub").unbind("click",sub);
        submit();
        $("#sub").bind("click",sub);
    }
    function submit() {

        var section = $("#expectSection").val();
        if($.isEmptyObject(section) || section == ''){
            mui.toast("请选择期望巡检季度");
            return;
        }
        var inAppoint = "";
        $.ajax({
            url : "cbsInspectionAppointmentController.do?existsAppoint",
            data : {
                snNum : $("#equipmentIdStr").val()
            },
            dataType : "json",
            async : false,
            success : function(data){
                if(data.success){
                    inAppoint = data.msg;
                }
            }
        })
        if(!$.isEmptyObject(inAppoint)){
           mui.alert('您选择的设备-'+inAppoint+"目前正在预约审批中，请不要重复提交");
            return;
        }

        var eSn = "";
        $.each($("#equipmentTypeStr").val().split(","), function (idx, itm) {
            if (itm == "1" || itm == "2") {
                eSn = localStorage.getItem(_Car.STORAGEKEY.xjyyEquipSn).split(",")[idx]
                return false;
            }
        });
        if (eSn != "") {
            mui.confirm("您提交的设备-" + eSn + "已经在本年度巡检计划中、请确认是否要提交巡检申请", "巡检提示", '', function (btValue) {
                if (btValue.index == 1) {
                    $("form").submit();
                }
            });
        } else {
            $("form").submit();
        }

    }

    $(function () {
        var selEquipItem = localStorage.getItem(_Car.STORAGEKEY.xjyyEquipSn);
        if($.isEmptyObject(selEquipItem)){
            subcallback();
        }
        var snStr = $.isEmptyObject(selEquipItem)?'':selEquipItem.substring(0,selEquipItem.length-1);
        if(snStr != ''){
            snStr = snStr.split(",");
            if(snStr.length > 2){
                for(var i=1;i<snStr.length;i++){
                    snStr[i] = snStr[i] +(i == snStr.length-1?"" :",");
                    if(i%2 != 0){
                        snStr[i] = snStr[i]+"<br/>";
                    }
                }
            }
            $("#snSpan").html(snStr.join(""));
        }
//        $("#snSpan").html($.isEmptyObject(selEquipItem)?'':selEquipItem.substring(0,selEquipItem.length-1));
        $("#sub").bind('click',sub);
        $("select[name='expectDate']").change(function(){
            expectDateChange();
        });

        $("select[name='expectSection']").change(function(){
            var selValue = $(this).val();
            if(isNaN(selValue) || selValue == ''){
                return ;
            }
            $.getJSON("cbsInspectionAppointmentController.do?checkSection",{section:selValue},function(data){
                if(!data.success){
                    mui.alert(data.msg,"提示");
                }
            })
        })
    })
</script>
</html>